import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '@/components/Index.vue'
import Login from '@/components/Login.vue'
import Home from '@/components/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: Login
  },
  {
    path: '/Index',
    name: 'Index',
    component: Index,
    children: [
      {
        path: '/Home',
        name: 'Home',
        meta: {
          title: '首页'
        },
        component: Home
      },
      // {
      //   path: '/Admin',
      //   name: 'admin',
      //   meta: {
      //     title: '管理员管理'
      //   },
      //   component: () => import('@/components/admin/AdminManage')
      // },
      // {
      //   path: '/User',
      //   name: 'user',
      //   meta: {
      //     title: '用户管理'
      //   },
      //   component: () => import('@/components/user/UserManage')
      // }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export function resetRouter(router) {
  const newRouter = new VueRouter({
    mode: 'history',
    routes: []
  })
  router.matcher = newRouter.matcher
  router.options.routes = [] // 清空现有的路由配置
}


export default router
